package com.todo.sight.application.convert;

import com.google.common.collect.Lists;
import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.common.enums.EnableTypeEnum;
import com.todo.common.common.enums.SourceEnum;
import com.todo.sight.application.entity.bo.*;
import com.todo.sight.application.entity.condition.PoiConditionBO;
import com.todo.sight.application.entity.condition.SightQueryConditionBO;
import com.todo.sight.application.iface.backend.request.*;
import com.todo.sight.application.iface.backend.response.QuerySightInfoByConditionResp;
import com.todo.sight.application.iface.backend.response.QuerySightPoiByConditionResp;
import com.todo.sight.application.iface.backend.response.QuerySightPoiDetailResp;
import com.todo.sight.application.iface.backend.response.SightInfoDetailResp;
import com.todo.sight.application.iface.frontend.request.SearchSightPoiParam;
import com.todo.sight.application.iface.frontend.request.SearchSightSummaryParam;
import com.todo.sight.application.iface.frontend.response.SightDetailVO;
import com.todo.sight.application.iface.frontend.response.SightInfoVO;
import com.todo.sight.application.iface.frontend.response.SightSummaryVO;
import com.todo.sight.common.enums.PoiBusinessTypeEnum;
import com.todo.sight.service.api.response.SightPoiDetailResponse;
import org.apache.commons.collections4.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author azhebuxing
 * @date 2024/5/16 17:19
 * @description
 */
public class SightInfoConvert {
    public static SightInfoDetailResp convertToSightInfoDetailResp(SightDetailBO sightDetailBO) {
        if (sightDetailBO == null) {
            return null;
        }
        SightInfoDetailResp sightInfoDetailResp = new SightInfoDetailResp();
        sightInfoDetailResp.setId(sightDetailBO.getId());
        sightInfoDetailResp.setTitle(sightDetailBO.getTitle());
        sightInfoDetailResp.setScore(sightDetailBO.getScore());
        sightInfoDetailResp.setHot(sightDetailBO.getHot());
        sightInfoDetailResp.setMainImg(sightDetailBO.getMainImg());
        sightInfoDetailResp.setAddress(sightDetailBO.getAddress());
        sightInfoDetailResp.setDesc(sightDetailBO.getDesc());
        if (sightDetailBO.getSuggest() != null) {
            SightDetailBO.Suggest suggest = sightDetailBO.getSuggest();
            SightInfoDetailResp.Suggest detailSuggest = new SightInfoDetailResp.Suggest();
            detailSuggest.setGuide(suggest.getGuide());
            detailSuggest.setSecuritySuggest(suggest.getSecuritySuggest());
            detailSuggest.setSuggestInfo(suggest.getSuggestInfo());
            detailSuggest.setTravelLimit(suggest.getTravelLimit());
            sightInfoDetailResp.setSuggest(detailSuggest);
        }
        if (sightDetailBO.getTicketInfo() != null) {
            SightDetailBO.TicketInfo ticketInfo = sightDetailBO.getTicketInfo();
            SightInfoDetailResp.TicketInfo detailTicketInfo = new SightInfoDetailResp.TicketInfo();
            detailTicketInfo.setTicketDiscountInfo(ticketInfo.getTicketDiscountInfo());
            detailTicketInfo.setTicketPrice(ticketInfo.getTicketPrice());
            detailTicketInfo.setTicketRule(ticketInfo.getTicketRule());
            sightInfoDetailResp.setTicketInfo(detailTicketInfo);
        }
        sightInfoDetailResp.setOpenTime(sightDetailBO.getOpenTime());
        sightInfoDetailResp.setProvince(sightDetailBO.getProvince());
        sightInfoDetailResp.setCity(sightDetailBO.getCity());
        sightInfoDetailResp.setImgList(sightDetailBO.getExtra() == null ? Lists.newArrayList() : sightDetailBO.getExtra().getImgList());
        sightInfoDetailResp.setIsShow(sightDetailBO.getIsShow());
        sightInfoDetailResp.setSlogan(sightDetailBO.getSlogan());
        sightInfoDetailResp.setPoiId(sightDetailBO.getPoiId());
        sightInfoDetailResp.setSource(sightDetailBO.getSource() == null ? null : sightDetailBO.getSource().getType());
        sightInfoDetailResp.setIsOpen(sightDetailBO.getIsOpen() == null ? null : sightDetailBO.getIsOpen().getType());
        return sightInfoDetailResp;
    }

    public static SightQueryConditionBO convertToSightQueryConditionBO(QuerySightInfoByConditionReq req) {
        if (req == null) {
            return null;
        }
        SightQueryConditionBO sightQueryConditionBO = new SightQueryConditionBO();
        sightQueryConditionBO.setPageIndex(req.getPageIndex());
        sightQueryConditionBO.setPageSize(req.getPageSize());
        sightQueryConditionBO.setProvince(req.getProvince());
        sightQueryConditionBO.setCity(req.getCity());
        sightQueryConditionBO.setId(req.getId());
        sightQueryConditionBO.setTitle(req.getTitle());
        sightQueryConditionBO.setPoiId(req.getPoiId());
        sightQueryConditionBO.setCurrentIndex(req.getCurrentIndex());
        return sightQueryConditionBO;
    }

    public static PageResult<QuerySightInfoByConditionResp> convertSightInfoResponseList(PageResult<SightBaseBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return new PageResult<>(Lists.newArrayList(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        List<QuerySightInfoByConditionResp> pageResultResp = new ArrayList<>();
        for (SightBaseBO sightBaseBO : pageResult.getResults()) {
            QuerySightInfoByConditionResp querySightInfoByConditionResp = new QuerySightInfoByConditionResp();
            querySightInfoByConditionResp.setId(sightBaseBO.getId());
            querySightInfoByConditionResp.setTitle(sightBaseBO.getTitle());
            querySightInfoByConditionResp.setHot(sightBaseBO.getHot());
            querySightInfoByConditionResp.setScore(sightBaseBO.getScore());
            querySightInfoByConditionResp.setIsOpen(sightBaseBO.getIsOpen() == null ? null : sightBaseBO.getIsOpen().getType());
            querySightInfoByConditionResp.setIsShow(sightBaseBO.getIsShow());
            querySightInfoByConditionResp.setMainImg(sightBaseBO.getMainImg());
            querySightInfoByConditionResp.setPoiId(sightBaseBO.getPoiId());
            querySightInfoByConditionResp.setProvince(sightBaseBO.getProvince());
            querySightInfoByConditionResp.setCity(sightBaseBO.getCity());
            pageResultResp.add(querySightInfoByConditionResp);
        }
        return new PageResult<>(pageResultResp, pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal(), pageResult.getCurrentIndex());
    }

    public static SightDetailBO buildSightDetailBO(InsertSightDetailReq req, SightPoiBO sightPoiBO) {
        if (req == null || sightPoiBO == null) {
            return null;
        }
        SightDetailBO sightDetailBO = new SightDetailBO();
        sightDetailBO.setTitle(req.getTitle());
        sightDetailBO.setHot(req.getHot());
        sightDetailBO.setScore(req.getScore());
        sightDetailBO.setIsOpen(req.getIsOpen() == null ? null : EnableTypeEnum.getByType(req.getIsOpen()));
        sightDetailBO.setIsShow(req.getIsShow());
        if (req.getTicketInfo() != null) {
            SightDetailBO.TicketInfo ticketInfo = new SightDetailBO.TicketInfo();
            ticketInfo.setTicketPrice(req.getTicketInfo().getTicketPrice());
            ticketInfo.setTicketDiscountInfo(req.getTicketInfo().getTicketDiscountInfo());
            ticketInfo.setTicketRule(req.getTicketInfo().getTicketRule());
            sightDetailBO.setTicketInfo(ticketInfo);
        }
        if (req.getSuggest() != null) {
            SightDetailBO.Suggest suggest = new SightDetailBO.Suggest();
            suggest.setSuggestInfo(req.getSuggest().getSuggestInfo());
            suggest.setTravelLimit(req.getSuggest().getTravelLimit());
            suggest.setSecuritySuggest(req.getSuggest().getSecuritySuggest());
            suggest.setGuide(req.getSuggest().getGuide());
            suggest.setSuggestInfo(req.getSuggest().getSuggestInfo());
            sightDetailBO.setSuggest(suggest);
        }
        if (CollectionUtils.isNotEmpty(req.getImgList())) {
            sightDetailBO.getExtra().setImgList(req.getImgList());
        }
        sightDetailBO.setOpenTime(req.getOpenTime());
        sightDetailBO.setAddress(req.getAddress());
        sightDetailBO.setSlogan(req.getSlogan());
        sightDetailBO.setDesc(req.getDesc());
        sightDetailBO.setLastUpdateUser(req.get_staff().getUsername());
        sightDetailBO.setMainImg(req.getMainImg());
        sightDetailBO.setPoiId(sightPoiBO.getId());
        sightDetailBO.setProvince(sightPoiBO.getProvince());
        sightDetailBO.setCity(sightPoiBO.getCity());
        sightDetailBO.setSource(SourceEnum.PLATFORM);
        sightDetailBO.setCreateUser(req.get_staff().getUsername());
        sightDetailBO.setLastUpdateUser(req.get_staff().getUsername());
        return sightDetailBO;
    }

    public static SightDetailBO convertSightDetailBO(UpdateSightDetailReq req) {
        if (req == null) {
            return null;
        }
        if (req.getId() != null) {
            SightDetailBO sightDetailBO = new SightDetailBO();
            sightDetailBO.setId(req.getId());
            sightDetailBO.setTitle(req.getTitle());
            sightDetailBO.setHot(req.getHot());
            sightDetailBO.setScore(req.getScore());
            sightDetailBO.setIsOpen(req.getIsOpen() == null ? null : EnableTypeEnum.getByType(req.getIsOpen()));
            sightDetailBO.setIsShow(req.getIsShow());
            if (req.getTicketInfo() != null) {
                SightDetailBO.TicketInfo ticketInfo = new SightDetailBO.TicketInfo();
                ticketInfo.setTicketPrice(req.getTicketInfo().getTicketPrice());
                ticketInfo.setTicketDiscountInfo(req.getTicketInfo().getTicketDiscountInfo());
                ticketInfo.setTicketRule(req.getTicketInfo().getTicketRule());
                sightDetailBO.setTicketInfo(ticketInfo);
            }
            if (req.getSuggest() != null) {
                SightDetailBO.Suggest suggest = new SightDetailBO.Suggest();
                suggest.setSuggestInfo(req.getSuggest().getSuggestInfo());
                suggest.setTravelLimit(req.getSuggest().getTravelLimit());
                suggest.setSecuritySuggest(req.getSuggest().getSecuritySuggest());
                suggest.setGuide(req.getSuggest().getGuide());
                suggest.setSuggestInfo(req.getSuggest().getSuggestInfo());
                sightDetailBO.setSuggest(suggest);
            }
            if (CollectionUtils.isNotEmpty(req.getImgList())) {
                sightDetailBO.getExtra().setImgList(req.getImgList());
            }
            sightDetailBO.setOpenTime(req.getOpenTime());
            sightDetailBO.setAddress(req.getAddress());
            sightDetailBO.setSlogan(req.getSlogan());
            sightDetailBO.setDesc(req.getDesc());
            sightDetailBO.setLastUpdateUser(req.get_staff().getUsername());
            sightDetailBO.setMainImg(req.getMainImg());
            sightDetailBO.setSource(SourceEnum.PLATFORM);
            return sightDetailBO;
        }
        return null;
    }

    public static QuerySightPoiDetailResp convertToQuerySightPoiDetailResp(SightPoiBO sightPoiBO) {
        if (sightPoiBO == null) {
            return null;
        }
        QuerySightPoiDetailResp querySightPoiDetailResp = new QuerySightPoiDetailResp();
        querySightPoiDetailResp.setId(String.valueOf(sightPoiBO.getId()));
        querySightPoiDetailResp.setName(sightPoiBO.getName());
        querySightPoiDetailResp.setAddress(sightPoiBO.getAddress());
        querySightPoiDetailResp.setCity(sightPoiBO.getCity());
        querySightPoiDetailResp.setDistrict(sightPoiBO.getDistrict());
        querySightPoiDetailResp.setTown(sightPoiBO.getTown());
        querySightPoiDetailResp.setPoiType(sightPoiBO.getPoiType());
        querySightPoiDetailResp.setTypeList(sightPoiBO.getTypeList());
        querySightPoiDetailResp.setLat(sightPoiBO.getLat() == null ? null : sightPoiBO.getLat().toPlainString());
        querySightPoiDetailResp.setLon(sightPoiBO.getLon() == null ? null : sightPoiBO.getLon().toPlainString());
        querySightPoiDetailResp.setOpenTime(sightPoiBO.getOpenTime());
        querySightPoiDetailResp.setProvince(sightPoiBO.getProvince());
        querySightPoiDetailResp.setRating(sightPoiBO.getRating());
        querySightPoiDetailResp.setIsShow(sightPoiBO.getIsShow() == null ? EnableTypeEnum.FORBIDDEN.getType() : sightPoiBO.getIsShow().getType());
        querySightPoiDetailResp.setBusinessType(sightPoiBO.getBusinessType() == null ? null : sightPoiBO.getBusinessType().getType());
        return querySightPoiDetailResp;
    }

    public static PoiConditionBO convertToPoiConditionBO(QuerySightPoiByConditionReq req) {
        if (req == null) {
            return null;
        }
        PoiConditionBO poiConditionBO = new PoiConditionBO();
        poiConditionBO.setPageIndex(req.getPageIndex());
        poiConditionBO.setPageSize(req.getPageSize());
        poiConditionBO.setCurrentIndex(req.getCurrentIndex());
        poiConditionBO.setName(req.getName());
        poiConditionBO.setPoiType(req.getPoiType() == null ? null : PoiBusinessTypeEnum.getByType(req.getPoiType()));
        poiConditionBO.setProvince(req.getProvince());
        poiConditionBO.setCity(req.getCity());
        poiConditionBO.setBusinessType(req.getBusinessType());
        return poiConditionBO;
    }

    public static PageResult<QuerySightPoiByConditionResp> convertToQuerySightPoiByConditionResp(PageResult<SightPoiBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return new PageResult<>(Lists.newArrayList(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        List<QuerySightPoiByConditionResp> results = new ArrayList<>();
        for (SightPoiBO sightPoiBO : pageResult.getResults()) {
            QuerySightPoiByConditionResp querySightPoiByConditionResp = new QuerySightPoiByConditionResp();
            querySightPoiByConditionResp.setId(String.valueOf(sightPoiBO.getId()));
            querySightPoiByConditionResp.setName(sightPoiBO.getName());
            querySightPoiByConditionResp.setCity(sightPoiBO.getCity());
            querySightPoiByConditionResp.setDistrict(sightPoiBO.getDistrict());
            querySightPoiByConditionResp.setPoiType(sightPoiBO.getPoiType());
            querySightPoiByConditionResp.setTypeList(sightPoiBO.getTypeList());
            querySightPoiByConditionResp.setLat(sightPoiBO.getLat() == null ? null : sightPoiBO.getLat().toPlainString());
            querySightPoiByConditionResp.setLon(sightPoiBO.getLon() == null ? null : sightPoiBO.getLon().toPlainString());
            querySightPoiByConditionResp.setProvince(sightPoiBO.getProvince());
            querySightPoiByConditionResp.setRating(sightPoiBO.getRating());
            querySightPoiByConditionResp.setIsShow(sightPoiBO.getIsShow() == null ? EnableTypeEnum.FORBIDDEN.getType() : sightPoiBO.getIsShow().getType());
            querySightPoiByConditionResp.setBusinessType(sightPoiBO.getBusinessType() == null ? null : sightPoiBO.getBusinessType().getType());
            results.add(querySightPoiByConditionResp);
        }
        return new PageResult<>(results, pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal(), pageResult.getCurrentIndex());
    }

    public static SightPoiBO insertReqConvertToSightPoiBO(InsertSightPoiReq req) {
        if (req == null) {
            return null;
        }
        SightPoiBO sightPoiBO = new SightPoiBO();
        sightPoiBO.setName(req.getName());
        sightPoiBO.setAddress(req.getAddress());
        sightPoiBO.setCity(req.getCity());
        sightPoiBO.setDistrict(req.getDistrict());
        sightPoiBO.setTown(req.getTown());
        sightPoiBO.setPoiType(req.getPoiType());
        sightPoiBO.setTypeList(req.getTypeList());
        sightPoiBO.setLat(new BigDecimal(req.getLat()));
        sightPoiBO.setLon(new BigDecimal(req.getLon()));
        sightPoiBO.setOpenTime(req.getOpenTime());
        sightPoiBO.setProvince(req.getProvince());
        sightPoiBO.setRating(req.getRating());
        sightPoiBO.setBusinessType(PoiBusinessTypeEnum.getByType(req.getBusinessType()));
        sightPoiBO.setIsShow(req.getIsShow() == null ? EnableTypeEnum.FORBIDDEN : EnableTypeEnum.getByType(req.getIsShow()));
        return sightPoiBO;
    }

    public static SightPoiBO updateReqconvertToSightPoiBO(UpdateSightPoiReq req) {
        SightPoiBO sightPoiBO = new SightPoiBO();
        sightPoiBO.setId(req.getId());
        sightPoiBO.setName(req.getName());
        sightPoiBO.setAddress(req.getAddress());
        sightPoiBO.setCity(req.getCity());
        sightPoiBO.setDistrict(req.getDistrict());
        sightPoiBO.setTown(req.getTown());
        sightPoiBO.setPoiType(req.getPoiType());
        sightPoiBO.setTypeList(req.getTypeList());
        sightPoiBO.setLat(new BigDecimal(req.getLat()));
        sightPoiBO.setLon(new BigDecimal(req.getLon()));
        sightPoiBO.setOpenTime(req.getOpenTime());
        sightPoiBO.setProvince(req.getProvince());
        sightPoiBO.setRating(req.getRating());
        sightPoiBO.setBusinessType(PoiBusinessTypeEnum.getByType(req.getBusinessType()));
        sightPoiBO.setIsShow(req.getIsShow() == null ? EnableTypeEnum.FORBIDDEN : EnableTypeEnum.getByType(req.getIsShow()));
        return sightPoiBO;
    }

    public static SightPoiDetailResponse convertToSightPoiDetailResponse(SightPoiBO sightPoiBO) {
        if (sightPoiBO == null) {
            return null;
        }
        SightPoiDetailResponse response = new SightPoiDetailResponse();
        response.setAddress(sightPoiBO.getAddress());
        response.setBusinessType(sightPoiBO.getBusinessType());
        response.setPoiId(sightPoiBO.getId());
        response.setName(sightPoiBO.getName());
        response.setProvince(sightPoiBO.getProvince());
        response.setTown(sightPoiBO.getTown());
        response.setOpenTime(sightPoiBO.getOpenTime());
        response.setCity(sightPoiBO.getCity());
        response.setDistrict(sightPoiBO.getDistrict());
        response.setLat(sightPoiBO.getLat());
        response.setLon(sightPoiBO.getLon());
        response.setRating(sightPoiBO.getRating());
        response.setTypeList(sightPoiBO.getTypeList());
        response.setIsShow(sightPoiBO.getIsShow());
        response.setOpenTime(sightPoiBO.getOpenTime());
        return response;
    }

    public static List<SightInfoVO> poiResponseconvertToSightInfoVOList(List<SightPoiBO> sightPoiBOList, Map<Long, Long> collectMap) {
        if (CollectionUtils.isEmpty(sightPoiBOList)) {
            return com.google.api.client.util.Lists.newArrayList();
        }
        List<SightInfoVO> sightInfoVOList = new ArrayList<>();
        for (SightPoiBO sightPoiResponse : sightPoiBOList) {
            SightInfoVO sightInfoVO = new SightInfoVO();
            sightInfoVO.setAddress(sightPoiResponse.getAddress());
            sightInfoVO.setCity(sightPoiResponse.getCity());
            sightInfoVO.setName(sightPoiResponse.getName());
            sightInfoVO.setPoiId(sightPoiResponse.getId());
            sightInfoVO.setProvince(sightPoiResponse.getProvince());
            sightInfoVO.setTypeList(sightPoiResponse.getTypeList());
            //TODO 待定信息
            sightInfoVO.setPoiTypeName("待定");
            sightInfoVO.setLat(String.valueOf(sightPoiResponse.getLat()));
            sightInfoVO.setLon(String.valueOf(sightPoiResponse.getLon()));
            sightInfoVO.setHasSightDetail(false);
            if (collectMap.containsKey(sightPoiResponse.getId())) {
                sightInfoVO.setHasSightDetail(true);
                Long sightId = collectMap.get(sightPoiResponse.getId());
                sightInfoVO.setSightId(sightId);
            }

            sightInfoVOList.add(sightInfoVO);
        }
        return sightInfoVOList;
    }

    public static SightDetailVO buildSightDetailVO(SightPoiBO sightPoiBO, SightDetailBO sightDetailBO) {
        if (sightPoiBO == null) {
            return null;
        }
        SightDetailVO sightDetailVO = new SightDetailVO();
        sightDetailVO.setSightDetail(convertToSightDetailVOSightDetail(sightDetailBO));
        sightDetailVO.setPoiInfo(convertToSightDetailVOPOIInfo(sightPoiBO));
        sightDetailVO.setSightInfo(convertToSightDetailVOSightInfo(sightDetailBO));
        return sightDetailVO;
    }

    private static SightDetailVO.SightInfo convertToSightDetailVOSightInfo(SightDetailBO sightDetailBO) {
        if (sightDetailBO == null) {
            return null;
        }
        SightDetailVO.SightInfo sightInfo = new SightDetailVO.SightInfo();
        sightInfo.setSlogan(sightDetailBO.getSlogan());
        sightInfo.setTitle(sightDetailBO.getTitle());
        sightInfo.setMainImg(sightDetailBO.getMainImg());
        sightInfo.setScore(sightDetailBO.getScore());
        sightInfo.setHot(sightDetailBO.getHot());
        sightInfo.setIsOpen(sightDetailBO.getIsOpen());
        sightInfo.setSightId(String.valueOf(sightDetailBO.getId()));
        return sightInfo;
    }

    private static SightDetailVO.SightDetail convertToSightDetailVOSightDetail(SightDetailBO sightDetailBO) {
        if (sightDetailBO == null) {
            return null;
        }
        SightDetailVO.SightDetail sightDetail = new SightDetailVO.SightDetail();
        sightDetail.setDesc(sightDetailBO.getDesc());
        sightDetail.setOpenTime(sightDetailBO.getOpenTime());
        if (sightDetailBO.getTicketInfo() != null) {
            SightDetailBO.TicketInfo ticketInfo = sightDetailBO.getTicketInfo();
            SightDetailVO.TicketInfo detailTicketInfo = new SightDetailVO.TicketInfo();
            detailTicketInfo.setTicketPrice(ticketInfo.getTicketPrice());
            detailTicketInfo.setTicketDiscountInfo(ticketInfo.getTicketDiscountInfo());
            detailTicketInfo.setTicketRule(ticketInfo.getTicketRule());
            sightDetail.setTicketInfo(detailTicketInfo);
        }
        if (sightDetailBO.getSuggest() != null) {
            SightDetailBO.Suggest suggest = sightDetailBO.getSuggest();
            SightDetailVO.Suggest detailSuggest = new SightDetailVO.Suggest();
            detailSuggest.setGuide(suggest.getGuide());
            detailSuggest.setSuggestInfo(suggest.getSuggestInfo());
            detailSuggest.setTravelLimit(suggest.getTravelLimit());
            detailSuggest.setSecuritySuggest(suggest.getSecuritySuggest());
            sightDetail.setSuggest(detailSuggest);
        }

        return sightDetail;
    }

    private static SightDetailVO.POIInfo convertToSightDetailVOPOIInfo(SightPoiBO sightPoiBO) {
        if (sightPoiBO == null) {
            return null;
        }
        SightDetailVO.POIInfo poiInfo = new SightDetailVO.POIInfo();
        poiInfo.setAddress(sightPoiBO.getAddress());
        poiInfo.setName(sightPoiBO.getName());
        poiInfo.setPoiId(String.valueOf(sightPoiBO.getId()));
        poiInfo.setPoiType(sightPoiBO.getPoiType());
        poiInfo.setTypeList(sightPoiBO.getTypeList());
        poiInfo.setLat(sightPoiBO.getLat());
        poiInfo.setLon(sightPoiBO.getLon());
        poiInfo.setProvince(sightPoiBO.getProvince());
        poiInfo.setCity(sightPoiBO.getCity());
        //TODO 待定信息
        poiInfo.setPoiTypeName("枚举待定");
        return poiInfo;
    }

    public static List<SightSummaryVO> buildSightSummaryVOList(List<SightBaseBO> sightBaseBOList, List<SightPoiBO> sightPoiBOList) {
        if (CollectionUtils.isEmpty(sightPoiBOList)) {
            return Lists.newArrayList();
        }
        Map<Long, SightBaseBO> poiIdMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(sightBaseBOList)) {
            poiIdMap = sightBaseBOList.stream().collect(Collectors.toMap(SightBaseBO::getPoiId, item -> item, (k1, k2) -> k1));
        }

        List<SightSummaryVO> result = new ArrayList<>();
        for (SightPoiBO sightPoiBO : sightPoiBOList) {
            SightSummaryVO sightSummaryVO = new SightSummaryVO();
            sightSummaryVO.setPoiInfo(convertToSightSummaryVOPOIInfo(sightPoiBO));
            SightBaseBO sightBaseBO = poiIdMap.get(sightPoiBO.getId());
            if (sightBaseBO != null) {
                sightSummaryVO.setSightInfo(convertToSightSummaryVOSightInfo(sightBaseBO));
            }

            result.add(sightSummaryVO);
        }
        return result;
    }

    private static SightSummaryVO.SightInfo convertToSightSummaryVOSightInfo(SightBaseBO sightBaseBO) {
        if (sightBaseBO == null) {
            return null;
        }
        SightSummaryVO.SightInfo sightInfo = new SightSummaryVO.SightInfo();
        sightInfo.setHot(sightBaseBO.getHot());
        sightInfo.setMainImg(sightBaseBO.getMainImg());
        sightInfo.setScore(sightBaseBO.getScore());
        sightInfo.setTitle(sightBaseBO.getTitle());
        sightInfo.setSlogan(sightBaseBO.getSlogan());
        sightInfo.setIsOpen(sightBaseBO.getIsOpen() == null ? null : sightBaseBO.getIsOpen().getType());
        sightInfo.setSightId(String.valueOf(sightBaseBO.getPoiId()));
        return sightInfo;
    }

    private static SightSummaryVO.POIInfo convertToSightSummaryVOPOIInfo(SightPoiBO sightPoiBO) {
        if (sightPoiBO == null) {
            return null;
        }
        SightSummaryVO.POIInfo poiInfo = new SightSummaryVO.POIInfo();
        poiInfo.setAddress(sightPoiBO.getAddress());
        poiInfo.setName(sightPoiBO.getName());
        poiInfo.setPoiId(String.valueOf(sightPoiBO.getId()));
        poiInfo.setPoiType(sightPoiBO.getPoiType());
        poiInfo.setTypeList(sightPoiBO.getTypeList());
        poiInfo.setLat(sightPoiBO.getLat());
        poiInfo.setLon(sightPoiBO.getLon());
        poiInfo.setProvince(sightPoiBO.getProvince());
        poiInfo.setCity(sightPoiBO.getCity());
        //TODO 待定信息
        poiInfo.setPoiTypeName("枚举待定");
        return poiInfo;
    }

    public static SearchSightSummaryBO convertToSearchSightSummaryBO(SearchSightSummaryParam param) {
        if (param == null) {
            return null;
        }
        SearchSightSummaryBO request = new SearchSightSummaryBO();
        request.setPageIndex(param.getPageIndex());
        request.setPageSize(param.getPageSize());
        request.setKeyword(param.getKeyword());
        request.setProvince(param.getProvince());
        request.setCity(param.getCity());
        return request;
    }

    public static SearchSightPoiBO convertToSearchSightPoiBO(SearchSightPoiParam param) {
        if (param == null) {
            return null;
        }
        SearchSightPoiBO request = new SearchSightPoiBO();
        request.setPageIndex(param.getPageIndex());
        request.setPageSize(param.getPageSize());
        request.setKeyword(param.getKeyword());
        request.setProvince(param.getProvince());
        request.setCity(param.getCity());
        return request;

    }

    public static PageResult<SightInfoVO> convertToSightInfoVOPageResult(PageResult<SearchSightPoiDetailBO> pageResult) {
        if (pageResult == null) {
            return PageResult.of(Lists.newArrayList(), 0, 0, 0);
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(Lists.newArrayList(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<SightInfoVO> result = new PageResult<>();
        List<SightInfoVO> responseList = Lists.newArrayList();
        for (SearchSightPoiDetailBO searchSightPoiDetailBO : pageResult.getResults()) {
            SightInfoVO response = new SightInfoVO();
            response.setPoiId(searchSightPoiDetailBO.getPoiId());
            response.setProvince(searchSightPoiDetailBO.getProvince());
            response.setCity(searchSightPoiDetailBO.getCity());
            response.setName(searchSightPoiDetailBO.getName());
            response.setAddress(searchSightPoiDetailBO.getAddress());
            response.setLat(searchSightPoiDetailBO.getLat());
            response.setLon(searchSightPoiDetailBO.getLon());
            response.setPoiType(searchSightPoiDetailBO.getPoiType());
            response.setHasSightDetail(searchSightPoiDetailBO.getHasSightDetail());
            response.setSightId(searchSightPoiDetailBO.getSightId());
            responseList.add(response);
        }
        result.setResults(responseList);
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setHasNext(pageResult.isHasNext());
        return result;
    }

    public static PageResult<SightSummaryVO> convertToSightSummaryVOPageResult(PageResult<SearchSightSummaryDetailBO> pageResult) {
        if (pageResult == null) {
            return PageResult.of(Lists.newArrayList(), 0, 0, 0);
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(Lists.newArrayList(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<SightSummaryVO> result = new PageResult<>();
        List<SightSummaryVO> responseList = Lists.newArrayList();
        for (SearchSightSummaryDetailBO searchSightSummaryResponse : pageResult.getResults()) {
            SightSummaryVO response = new SightSummaryVO();

            SightSummaryVO.POIInfo poiInfoVO = new SightSummaryVO.POIInfo();
            SearchSightSummaryDetailBO.SightPoi poiInfo = searchSightSummaryResponse.getPoiInfo();
            poiInfoVO.setPoiId(String.valueOf(searchSightSummaryResponse.getPoiId()));
            poiInfoVO.setLat(poiInfo.getLat());
            poiInfoVO.setLon(poiInfo.getLon());
            poiInfoVO.setName(poiInfo.getName());
            poiInfoVO.setAddress(poiInfo.getAddress());
            poiInfoVO.setCity(poiInfo.getCity());
            poiInfoVO.setProvince(poiInfo.getProvince());
            poiInfoVO.setPoiType(poiInfo.getPoiType());
            poiInfoVO.setTypeList(poiInfo.getTypeList());
            poiInfoVO.setTypeList(poiInfo.getTypeList());
            response.setPoiInfo(poiInfoVO);

            SightSummaryVO.SightInfo sightInfoVO = new SightSummaryVO.SightInfo();
            SearchSightSummaryDetailBO.SightSummary sightInfo = searchSightSummaryResponse.getSightSummary();
            sightInfoVO.setHot(sightInfo.getHot());
            sightInfoVO.setTitle(sightInfo.getTitle());
            sightInfoVO.setIsOpen(sightInfo.getIsOpen());
            sightInfoVO.setMainImg(sightInfo.getMainImg());
            sightInfoVO.setScore(sightInfo.getScore());
            sightInfoVO.setSlogan(sightInfo.getSlogan());
            sightInfoVO.setSightId(String.valueOf(searchSightSummaryResponse.getSightId()));
            response.setSightInfo(sightInfoVO);
            responseList.add(response);
        }

        result.setResults(responseList);
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setHasNext(pageResult.isHasNext());
        return result;
    }
}
